package com.bytedance.common.plugin.interfaces.pushmanager.message;

import android.app.IntentService;
import android.content.Context;
import android.content.Intent;
import android.support.design.a;

import com.bytedance.common.plugin.interfaces.pushmanager.MessageConstants;
import com.bytedance.common.plugin.interfaces.pushmanager.client.SsPushManager;
import com.bytedance.common.plugin.interfaces.pushmanager.setting.PushSetting;
import com.bytedance.common.utility.Logger;

public abstract class MessageReceiverService extends IntentService {
    private static final String TAG = "MessageReceiverService";

    public MessageReceiverService() {
        super("MessageReceiverService");
    }

    public static void handleRegisterMessage(Context arg2, int arg3, String arg4, int arg5) {
        if (arg2 == null) {
            return;
        }

        if (arg3 != 0 && arg3 != 2) {
            return;
        }

        switch (arg3) {
            case 0: {
                try {
                    label_7:
                    SsPushManager.inst().setAlias(arg2, PushSetting.getInstance().getDeviceId(), arg5);
                    PushRegisterResultHandler.inst().onPushRegisterSuccess(arg2, arg5, arg4);
                } catch (Throwable v0) {
                }

                return;
            }
            case 2: {
                try {
                    PushRegisterResultHandler.inst().onPushRegisterFail(arg2, arg5, arg4);
                } catch (Throwable v0) {
                }
                return;
            }
        }

        return;

    }

    public void onCreate() {
        super.onCreate();
        MessageConstants.getIMessageDepend().tryHookInit(((Context) this));
    }

    public abstract void onHandMessage(Context arg1, int arg2, String arg3, int arg4, String arg5);

    protected void onHandleIntent(Intent arg2) {
        try {
            this.onReceive(((Context) this), arg2);
        } catch (Throwable v0) {
            v0.printStackTrace();
        }
    }

    public void onReceive(Context arg8, Intent arg9) {
        String v3;
        int v6 = 2;
        if (arg8 != null && arg9 != null) {
            String v0 = arg9.getAction();
            if (v0 != null) {
                Logger.d("MessageReceiverService", "action = " + v0);
            }

            if (!PushSetting.getInstance().isPushNotifyEnable()) {
                Logger.i("MessageReceiverService", "notify enable = " + PushSetting.getInstance().isPushNotifyEnable());
                return;
            }

            try {
                if ("com.ss.android.message".equals(v0)) {
                    v3 = SsPushManager.inst().handleMySelfPushIntent(arg9);
                    if (a.isTextEmpty(v3)) {
                        return;
                    }

                    Logger.d("MessageReceiverService", "message received, msg is: " + v3);
                    this.onHandMessage(arg8, 1, v3, 2, null);
                    return;
                }

                if (!"com.ss.android.xiaomi.message".equals(v0) && !"com.ss.android.umeng.message".equals(v0) && !"com.ss.android.gcm.message".equals(v0) && !"com.ss.android.hw.message".equals(v0) && !"com.ss.android.mz.message".equals(v0) && !"com.ss.android.aliyun.message".equals(v0) && !"com.ss.android.oppo.message".equals(v0)) {
                    return;
                }

                int v2 = arg9.getIntExtra("message_type", -1);
                v3 = arg9.getStringExtra("message_obj");
                int v4 = arg9.getIntExtra("message_from", -1);
                String v5 = arg9.getStringExtra("message_extra");
                if (v2 != 0 && v2 != v6) {
                    this.onHandMessage(arg8, v2, v3, v4, v5);
                    return;
                }

                MessageReceiverService.handleRegisterMessage(arg8, v2, v3, v4);
            } catch (Exception v0_1) {
                v0_1.printStackTrace();
            }
        }
    }

    public int onStartCommand(Intent arg2, int arg3, int arg4) {
        super.onStartCommand(arg2, arg3, arg4);
        return 2;
    }
}

